import api from "@/api/apiConfig";
import ajax from "@/api/http";
import store from "@/store";
import router from "@/router";

export default {
  goPage(routerName, params, query) {
    router.push({
      name: routerName,
      params: { id: params },
      query: { info: query }
    });
  },
  getInfo(cb) {
    if (localStorage.getItem("mtoken")) {
      ajax
        .post(api.personalCenter)
        .then(res => {
          store.dispatch("changeLogin", true);
          store.dispatch("changeValidate", res.data.is_check);
          store.dispatch("changeSetPay", res.data.is_pay_password);
          store.dispatch("changeCard", res.data.is_card);
          store.dispatch("changeUserImg", res.data.img_head);
          store.dispatch("changeUsername", res.data.username);
          store.dispatch("changeUserOrder", res.data.order);
          store.dispatch("changeLoginTime", res.data.login_time);
          store.dispatch("changeUserMobile", res.data.mobile);
          store.dispatch("changeUserMoney", res.data.money);
          cb && cb();
        })
        .catch(() => {
          cb && cb();
        });
    } else {
      cb && cb();
    }
  }
};
